(ns pe.p14)

(defn seqfn [n]
  (cond (= 1 n) 1
        (even? n) (quot n 2)
        :else (inc (* 3 n))))

(defn p14seq [n] (iterate seqfn n))

(defn seqsize [s]
  (inc (count (take-while #(> % 1) s))))

(defn chain-sizes [n]
  (let [r (range 2 (inc n))]
    (map #(list (seqsize (p14seq %)) %) r)))

(defn find-max [a b]
  (let [len1 (first a) len2 (first b)]
    (cond
      (> len1 len2) a
      :else b)))

(print (reduce find-max '(0 0) (chain-sizes 1000000)))